<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>setTimeout()|setInterval()</title>
</head>
<body>
    <script type="text/javascript">
        // 延迟性操作
        /*
        window.setTimeout(function(){
            console.log('mjj');
        },2000)
        console.log('xiongdada');
        */

        var num = 0;
        var timer = null;
        timer = setInterval(function(){
            num++;
            if (num > 5){
                clearInterval(timer);
                return;
            }
            console.log('num:' + num);
        },1000);
    </script>

</body>
</html>